<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" href="../style.css" type="text/css" />
</head>
<?php
		include_once "../inc/docroot.php";
		include_once PATH."inc/class.autores.inc.php";
		$autores = new autores($db);
		if(isset($_GET['campaign']))$campaign_id = $_GET['campaign'];
		if(isset($_GET['message']))$message_id = $_GET['message'];
		if(isset($_GET['edit']))$edit = $_GET['edit'];
		if(isset($_GET['delete']))$delete = $_GET['delete'];

?>

<body>
<div>
  <div class="autores_header">
    <?php
	   if(!empty($_POST['ishtml']) && !empty($_POST['delay']) &&!empty($_POST['message']) 
	   && isset($message_id) && isset($edit) && $edit == 1){
		    echo "<br /><br />";
			echo $autores->editmessage();
			?>
			<script>
			window.opener.location.reload();
			//window.close();
            </script>
            <?php
			
	   }
	   else if(isset($message_id) && isset($campaign_id) && isset($delete) && $delete == 1){
		    echo "<br /><br />";
			echo $autores->deletemessage();
			?>
			<script>
			window.opener.location.reload();
			window.close();  
            </script>
            <?php
	   }
       else if(!empty($_POST['ishtml']) && !empty($_POST['delay']) &&!empty($_POST['message'])) {
        	echo "<br /><br />";
			echo $autores->addmessage();
			?>
			<script>
				window.opener.location.reload();
            </script>
            <?php
	   }
	   else{	   
?>
    <br />
    <br />
    <label>Please fill all the fields.</label>
    <?php
	   }
?>
    <br />
    <br />
<?php
	if(isset($edit) && $edit == 1){?>
    	<label> EDIT MESSAGE <?php echo $message_id; ?></label>
	<?php
    }
	else if(isset($delete)){

		echo "<br /><br /><label> Are you sure to DELETE Message:". $message_id ."?</label><br /><br />";
?>
		<form method="post" action="addnewmessage.php?campaign=<?php echo $campaign_id;?><?php if(isset($delete) && isset($message_id))echo '&delete=1&message='.$message_id;?>" name="deletemessageform" id="deletemessageform">
  <input type="submit" name="deletemessageinput" id="deletemessageinput" value="Delete message" class="btn btn--blue btn--m" />
  		
<?php		
	}
	else {?>
		<label> ADD A NEW MESSAGE </label>
	<?php }
?>
  </div>
  
  <?php
	if(!isset($delete)){
?>
  
  <form method="post" action="addnewmessage.php?campaign=<?php echo $campaign_id;?><?php if(isset($edit) && isset($message_id))echo '&edit=1&message='.$message_id;?>" name="addmessageform" id="addmessageform" enctype="multipart/form-data">
    <div style="font-size:9px;" align="center"> <br />
      
      <select name="ishtml" id="ishtml" width="75" style="width: 75px; height:20px; font-size:15px;" height="20">
  			<option value="1">TRUE</option>
  			<option value="0">FALSE</option>
      </select>
      <br />
      <label for="ishtml">HTML</label>
      <br />
      <br />
      
      <input type="text" name="delay" id="delay" width="75" style="text-align:center; width: 75px; height:20px; font-size:15px;" height="20"/>
      <label for="delay">Delay(in mins)</label>
      <br />
      <br />
      
      <input type="file"  name="file1" id="file1" value="file1" style=" font-size:11px;">
      <label for="file1">Add Attachment</label>
      
      <br />
      <br />
      <input type="file"  name="file2" id="file2" value="file2" style=" font-size:11px;">
      <label for="file2">Add Attachment</label>
      
      <br />
      <br />
      <input type="file"  name="file3" id="file3" value="file3" style=" font-size:11px;">
      <label for="file3">Add Attachment</label>
      
      <br />
      <br />
      <textarea name="message" id="message" style="text-align:center" rows="5" cols="40"></textarea>
      <br />
      <label for="message">Message</label>
      <br />
      <br />
      
      
      <br />
      <br/ >
      <input type="submit" name="addmessageinput" id="addmessageinput" value="Save message" class="btn btn--blue btn--m" />
    </div>
  </form>
 <?php } ?>
</div>
</body>
